@extends('admin.layouts.app')

@section('right-content')
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>编辑兑换商品</legend>
    </fieldset>

    <form class="layui-form" action="" style="margin-right: 60%">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <input type="text" name="item_name" value="{{ $gift->item_name }}" lay-verify="required" autocomplete="off" placeholder="请输入商品名称" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="kind" >
                    <option value="1" @if($gift->kind = 1) selected @endif>美食</option>
                    <option value="2" @if($gift->kind = 2) selected @endif>旅游</option>
                    <option value="3" @if($gift->kind = 3) selected @endif>其他</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">图片编码</label>
            <div class="layui-input-inline">
                <input type="text" name="icon" value="{{ $gift->icon }}" lay-verify="required" placeholder="请输入物品图片编码" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">需要和七牛云图片编号对应</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所需积分</label>
            <div class="layui-input-inline">
                <input type="text" name="price" value="{{ $gift->price }}" lay-verify="required|number" placeholder="请输入所需积分" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-block">
                <input type="text" name="addr" value="{{ $gift->addr }}" lay-verify="" placeholder="请输入地址" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">兑换日期</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" value="{{ $gift->over_time }}" lay-verify="required" name="over_time" id="over_time" placeholder="请输入兑换日期" readonly="">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-inline">
                <input type="text" name="max_num" value="{{ $gift->max_num }}" lay-verify="" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="note">{{ $gift->note }}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否推荐</label>
            <div class="layui-input-block">
                <input type="radio" name="recommand" value="1" title="是" @if ($gift->recommand == 1) checked @endif>
                <input type="radio" name="recommand" value="0" title="否" @if ($gift->recommand == 0) checked @endif>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="order_id" value="{{ $gift->order_id }}" lay-verify="" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>


       <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="enable" value="1" title="上线" @if ($gift->enable == 1) checked @endif>
                <input type="radio" name="enable" value="0" title="下线" @if ($gift->enable == 0) checked @endif>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="sub" data-url="{{ route('gifts.update', ['id' => $gift->id]) }}">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection

@section('my-js')
<script type="text/javascript">
   layui.use(['form','laydate'], function(){
       var form = layui.form, laydate = layui.laydate;

       var start = laydate.render({
            elem: '#over_time',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            calendar: true,
       });



      form.on('submit(sub)', function(data){
        var url = $(this).attr('data-url');
        commonAjaxSubmit(url, 'PUT');

      })
    });
</script>
@endsection